<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    :root {
      --mian-bg: #fff;
      --main-color: #000;
    }

    .dark {
      --mian-bg: #000;
      --main-color: #fff;
    }
  </style>
</head>

<body>
  <div class="box">


  </div>
</body>
<script>
  
  let dom = document.documentElement;//获取document

  let styles = getComputedStyle(dom);//获取styles对象
  let val = styles.getPropertyValue('--mian-bg')// 获取属性--main-bg的值
  console.log('styles',styles,`s${val}s`);
  
  // document.style.setProperty('--mian-bg','#000')
</script>

</html>